﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Card.DAL;
using Card.Entity;
using System.Data;

namespace Card.BLL
{
    public class AreaManager
    {
        private static AREA dal = new AREA();
        public AreaManager()
        { }
        #region  成员方法
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public static bool Exists(int ID, Security.Passport passport)
        {
            return dal.Exists(ID, passport);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public static bool Add(Area entity, Security.Passport passport)
        {
            return dal.Add(entity, passport);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public static bool Update(Area entity, Security.Passport passport)
        {
            return dal.Update(entity, passport);
        }

        /// <summary>
        /// 保存实体
        /// </summary>
        public static bool Save(Area entity, Security.Passport passport)
        {
            if (dal.Exists(entity.ID, passport))
            {
                return dal.Update(entity, passport);
            }
            else
            {
                return dal.Add(entity, passport);
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public static bool Delete(int ID, Security.Passport passport)
        {
            return dal.Delete(ID, passport);
        }



        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public static Area GetEntity(int ID, Security.Passport passport)
        {
            return dal.GetEntity(ID, passport);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public static DataSet GetList(string strWhere, Security.Passport passport)
        {
            return dal.GetList(strWhere, passport);
        }

        public static List<Entity.Area> GetListByParentID(int parentID, Security.Passport passport)
        {
            return dal.GetListByParentID(parentID, passport);
        }

        public static List<Entity.Area> GetParentListByID(int areaID, Security.Passport passport)
        {
            return dal.GetParentListByID(areaID, passport);
        }

        /// <summary>
        /// 得到兄弟地区
        /// </summary>
        /// <param name="areaID"></param>
        /// <param name="passport"></param>
        /// <returns></returns>
        public static List<Entity.Area> GetBrotherAreaByID(int areaID, Security.Passport passport)
        {
            return dal.GetBrotherAreaByID(areaID, passport);
        }
        /// <summary>
        /// 获得省市区名称
        /// </summary>
        /// <param name="areaID"></param>
        /// <param name="passport"></param>
        /// <returns></returns>
        public static DataTable GetAreaNameByID(int areaID, Security.Passport passport)
        {
            return dal.GetAreaNameByID(areaID, passport);
        }

        /// <summary>
        /// 获得省市区名称
        /// </summary>
        /// <param name="areaID">区ID</param>
        /// <param name="separator">间隔符号</param>
        /// <param name="passport"></param>
        /// <returns></returns>
        public static string GetAreaNameByID(int areaID, string separator, Security.Passport passport)
        {
            DataTable dtData = dal.GetAreaNameByID(areaID, passport);
            if (dtData != null && dtData.Rows.Count > 0)
            {
                return string.Format("{0}{3}{1}{3}{2}",
                    dtData.Rows[0]["PROVINCENAME"].ToString(),
                    dtData.Rows[0]["CITYNAME"].ToString(),
                    dtData.Rows[0]["AREANAME"].ToString(),
                    separator);

            }
            return string.Empty;
        }

        /// <summary>
        /// 是否有子节点
        /// </summary>
        /// <param name="parentID"></param>
        /// <param name="passport"></param>
        /// <returns></returns>
        public static bool ExistsChildren(int parentID, Security.Passport passport)
        {
            return dal.ExistsChildren(parentID, passport);
        }

        /// <summary>
        /// 得到地区ID,通areaName模糊查询,取第一条数据,没有找到则返回 0
        /// </summary>
        /// <param name="areaName"></param>
        /// <param name="passport"></param>
        /// <returns></returns>
        public static int GetAreaID(string areaName, Security.Passport passport)
        {
            return dal.GetAreaID(areaName, passport);
        }
        /// <summary>
        /// 通过站点代码获得所属城市
        /// </summary>
        /// <param name="siteCode"></param>
        /// <param name="passport"></param>
        /// <returns></returns>
        public static DataTable GetAreaByCode(string siteCode, Security.Passport passport)
        {
            return dal.GetAreaByCode(siteCode, passport);
        }
        /// <summary>
        /// 分站代码是否存在
        /// </summary>
        /// <param name="siteCode"></param>
        /// <param name="passport"></param>
        /// <returns></returns>
        public static bool ExistsSiteCode(string siteCode,int areaID,  Security.Passport passport)
        {
            return dal.ExistsSiteCode(siteCode,areaID, passport);
        }

        /// <summary>
        /// 得到所有地区
        /// </summary>
        /// <returns></returns>
        public static List<Entity.Area> GetAllArea()
        {
            return dal.GetAllArea();
        }
        #endregion  成员方法
    }
}
